package com.xy.job.executor.core.job

import org.slf4j.LoggerFactory
import java.util.concurrent.ConcurrentHashMap

object JobHandlerRegistry {

    private val log = LoggerFactory.getLogger(this.javaClass)
    private val jobHandlerMap = ConcurrentHashMap<String, IJobHandler>()

    init {
        register(ScriptJobHandler::class.simpleName!!, ScriptJobHandler())
    }

    fun register(handlerName: String, jobHandler: IJobHandler) {
        log.info("register jobHandler $handlerName")
        jobHandlerMap[handlerName] = jobHandler
    }

    fun find(handlerName: String): IJobHandler {
        return jobHandlerMap[handlerName] ?: throw RuntimeException("handler [$handlerName] not exist")
    }
}